#include <iostream>
using namespace std;
#include <string>

#include "console.h"
#include "world.h"

string input;
World world;

void start() {    
    welcome();
    bool continueInput = true;    
    while (continueInput) {
        input = getInput();
        continueInput = parse();
    }
}

void welcome() {
    cout << endl << "Welcome to Charged Particle Simulator!" << endl 
        << "Type 'help' to see all available commands." << endl << endl;
}

string getInput() {
    cout << ">> ";
    string in;
    cin >> in;
    return in;
}

bool parse() {
    if (input == "exit") {
        return false;
    }
    else if (input == "add") {
        addParticle();
    }
    else if (input == "remove") {
        removeParticle();
    }
    else if (input == "update") {
        world.update();
    }
    else if (input == "list") {
        world.showParticles();
    }
    else if (input == "help") {
        help();
    }
    else {
        cout << "ERROR: Command not recognized!" << endl;
    }
    return true;
}

void addParticle() {
    double x, y, charge;
    cout << "x     : "; cin >> x;
    cout << "y     : "; cin >> y;
    cout << "charge: "; cin >> charge;
    world.addParticle(x, y, charge, 0, 0);
}

void removeParticle() {
    int n;
    world.showParticles();
    cout << "particle number: ";
    cin >> n;
    world.removeParticle(n);
}

void help() {
    cout 
        << "exit   : quit this program" << endl
        << "add    : add a new particle" << endl
        << "update : update the particles" << endl
        << "remove : remove a particle" << endl
        << "list   : list all particles" << endl
        << "help   : show this menu" << endl;
}

